package com.nhjf.admin.common.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;


public class DeliveryProperties {
	 
	private  Properties properties = null;
	private  final String PROP_PATH = "/prop/delivery.properties";
	private  static DeliveryProperties sysProperties;
	private  DeliveryProperties() {
		init();
	}
	private void init(){
		try {
			InputStream inputStream = getInputStream();
			properties = new Properties();
			properties.load(inputStream);
			inputStream.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			LogMessage.logwrite(this.getClass(), e.getMessage());
		}
	}
   
	private InputStream getInputStream(){
	   return DeliveryProperties.class.getResourceAsStream(PROP_PATH);
    }
	
	public Properties getProp(String path) {
		Properties props = new Properties();
		InputStream in = null;
		try {
			//讲文件信息读取到输出流
			in = DeliveryProperties.class.getResourceAsStream(path);
			props.load(in);
			return props;
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return props;
	}
	
	
	public static DeliveryProperties getInstance() {
		if (sysProperties == null) {
			sysProperties = new DeliveryProperties();
        }
		return sysProperties;
	}
	
	public String get(String key){
		if (properties == null) {
			init();
		}
		if (StringUtils.isBlank(key)) {
			return "";
		} else {
			return properties.getProperty(key);
		}		 
	}
	
}
